//
//  TokenInterceptor.swift
//  SwiftCode
//
//  Created by yuhus on 2023/8/4.
//

import Alamofire

final class TokenAdapter: RequestInterceptor {
  let accessToken: String = "this is custom token"
  
  func adapt(_ urlRequest: URLRequest, using state: RequestAdapterState, completion: @escaping (Result<URLRequest, Error>) -> Void) {
    print(#fileID, "requestID: \(state.requestID)")
    var urlRequest = urlRequest
    urlRequest.headers.add(name: "token", value: accessToken)
    completion(.success(urlRequest))
  }
}

final class HeaderAdapter: RequestInterceptor {
  func adapt(_ urlRequest: URLRequest, using state: RequestAdapterState, completion: @escaping (Result<URLRequest, Error>) -> Void) {
    var urlRequest = urlRequest
    [
      "Content-Type": "application/json",
      "Accept-Language": "en-US",
      "platform": "ios",
      "device_id": "1CCC2D79-01A9-4C27-86BB-8D96F9E7C2D9",
      "self_package_name": "com.meta.gpark",
      "app_version_code": "10000"
    ]
      .forEach { urlRequest.headers.add(name: $0, value: $1) }
    completion(.success(urlRequest))
  }
}
